package cn.gailvlun.gll.util;

import com.google.i18n.phonenumbers.PhoneNumberUtil;

import java.util.Locale;



public class PhoneUtil {

    
    public static int getCountryCodeByDefault() {
        return getCountryCodeByDefault(86);
    }

    
    public static int getCountryCodeByDefault(int defaultCountryCode) {
        Locale locale = Locale.getDefault();
        int countryCode = PhoneNumberUtil.getInstance().getCountryCodeForRegion(locale.getCountry());
        return countryCode == 0 ? defaultCountryCode : countryCode;
    }

    private static final String REGEX_PHONE = "^0?1[3|4|5|7|8][0-9]\\d{8}$";

    public static boolean validatePhoneNumber(String phone) {
        return !isEmpty(phone) && phone.matches(REGEX_PHONE);

    }

    public static boolean isEmpty(String... content) {
        if (content == null) {
            return true;
        }

        for (String s : content) {
            if (s == null || s.trim().equals("")) {
                return true;
            }
        }
        return false;
    }
}
